import tkinter as tk
 
def create_spinboxes(root):
    # 时间选择器的起始时间和结束时间
    start_time = '00:00:00'
    end_time = '23:59:59'
 
    # 时分秒的Spinbox
    def create_spinbox(root, side, start, end, increment):
        spinbox = tk.Spinbox(root, from_=start, to=end, increment=increment, width=5)
        spinbox.pack(side=side, padx=5)
        return spinbox
 
    # 创建小时Spinbox
    hour_spinbox = create_spinbox(root, tk.LEFT, 0, 23, 1)
    # 创建分钟Spinbox
    minute_spinbox = create_spinbox(root, tk.LEFT, 0, 59, 1)
    # 创建秒Spinbox
    second_spinbox = create_spinbox(root, tk.LEFT, 0, 59, 1)
 
    # 返回选择的时间
    def get_time():
        hour = hour_spinbox.get()
        minute = minute_spinbox.get()
        second = second_spinbox.get()
        return f"{hour}:{minute}:{second}"
 
    return get_time
 
def main():
    root = tk.Tk()
    root.title("时间选择器")
 
    get_time = create_spinboxes(root)
    selected_time = tk.Label(root, text=get_time(), width=10)
    selected_time.pack()
 
    # 更新时间显示
    def update_time():
        selected_time.config(text=get_time())
 
    # 绑定Spinbox变化事件
    # hour_spinbox.bind('<<Increment>>', update_time)
    # minute_spinbox.bind('<<Increment>>', update_time)
    # second_spinbox.bind('<<Increment>>', update_time)
 
    root.mainloop()
 
if __name__ == "__main__":
    main()